home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / sphigs / sph_mac.hqx / SRGP port to 5.0 (compressed) / SRGP_SPHIGS Root / MacSPHIGS / sph_attrib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-14  |  2.4 KB  |  90 lines

  1. #include "HEADERS.h"
  2. #include "sphigslocal.h"
  3.  
  4.  
  5.  
  6. /** LOADING A MICROCOLOR INTO THE SPHIGS VIRTUAL COLORTABLE 
  7. Only for loading into the very small microcolor table, excluding the
  8. first two microcolors (0 and 1).
  9. **/
  10.  
  11. #ifdef __MSDOS__
  12. extern palData srgp__common_color_pal[1];
  13. #endif
  14.  
  15. #include "sph_attrib.proto.h"
  16.  
  17. void SPH_loadCommonColor (int colorindex, char *name)
  18. {
  19.    register i;
  20.    unsigned short  r, g, b;     /* A SHADE OF THE ACTUAL COLOR */
  21.    unsigned short rr,gg,bb;    /* ACTUAL COLOR */
  22.    int basethiscolor;
  23.    double bias;
  24.  
  25.    if ( ! IS_CHANGEABLE_COLOR_INDEX(colorindex))
  26.       return;
  27.  
  28.    SRGP_loadCommonColor (colorindex, name);
  29.    
  30.    if ( ! IS_A_FLEXICOLORINDEX(colorindex))
  31.       return;
  32.       
  33.    /* THE FOLLOWING EXECUTED ONLY IF ACTUAL FLEXICOLOR */
  34. #ifdef __MSDOS__
  35.    rr = srgp__common_color_pal[0].palRed;
  36.    gg = srgp__common_color_pal[0].palGreen;
  37.    bb = srgp__common_color_pal[0].palBlue;
  38. #else
  39.    SRGP_inquireColorTable (colorindex, 1, &rr, &gg, &bb);
  40. #endif
  41.  
  42.    basethiscolor = BASE_OF_SHADE_LUT_ENTRIES + 
  43.       (colorindex-2)*NUM_OF_SHADES_PER_FLEXICOLOR;
  44.  
  45.    for (i=0; i<NUM_OF_SHADES_PER_FLEXICOLOR; i++) {
  46.       bias = 
  47.      0.35 + 
  48.         (0.65 * ((double)(i+1) / (double)NUM_OF_SHADES_PER_FLEXICOLOR));
  49.       r = rr * bias;
  50.       g = gg * bias;
  51.       b = bb * bias;
  52.       SRGP_loadColorTable ((basethiscolor+i), 1, &r, &g, &b);
  53.    }
  54. }
  55.  
  56.  
  57.  
  58. extern int srgp__available_depth;
  59.  
  60. void SPH__initColorTable (int shades_per_flexicolor)
  61. {
  62.    register i;
  63.    int num_of_srgp_colors = (1 << SRGP_inquireCanvasDepth());
  64.    
  65. #ifdef THINK_C
  66.    /* On Mac, very highest LUT entry must be reserved and stay black! */
  67.    if (num_of_srgp_colors == (1 << srgp__available_depth))
  68.       num_of_srgp_colors--; 
  69. #endif
  70.    
  71.    /* Compute the number of flexicolors that will be possible */
  72.    /* I assume that C truncates when division is performed. */
  73.    NUM_OF_FLEXICOLORS = 
  74.       (num_of_srgp_colors - 2) / (1 + shades_per_flexicolor);
  75.                
  76.    if (NUM_OF_FLEXICOLORS < 1) {
  77.       NUM_OF_FLEXICOLORS = 0;
  78.       BASE_OF_SHADE_LUT_ENTRIES = num_of_srgp_colors;
  79.    }
  80.    else {
  81.       /* Calculate dependent statistics */
  82.       NUM_OF_SHADES_PER_FLEXICOLOR = shades_per_flexicolor;
  83.       BASE_OF_SHADE_LUT_ENTRIES = 
  84.      num_of_srgp_colors - (NUM_OF_FLEXICOLORS * shades_per_flexicolor);
  85.       /* Load black into all the changeable color-table entries */
  86.       for (i=2; i<BASE_OF_SHADE_LUT_ENTRIES; i++)
  87.           SPH_loadCommonColor (i, "black");
  88.    }
  89. }
  90.